import 'package:custom_button_builder/custom_button_builder.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class AppButton extends StatelessWidget {
  final Function onPressed;
  final String? content;
  final double? width;
  final double? height;
  final double borderRadius;
  final Color backgroundColor;
  final Color? disableColor;
  /// 禁止点击
  final bool disable;
  final Widget? child;
  final Decoration? decoration;
  final bool animate;
  final Duration? throttle;

  const AppButton({
    super.key,
    required this.onPressed,
    this.content,
    this.width,
    this.height,
    this.borderRadius = 90,
    this.backgroundColor = const Color(0xFFE34234),
    this.disable = false,
    this.disableColor,
    this.child,
    this.decoration,
    this.animate = true,
    this.throttle
  });

  @override
  Widget build(BuildContext context) {
    return CustomButton(
      width: width ?? 600.w,
      height: height ?? 80.h,
      pressed: disable ? (animate ? Pressed.pressed : Pressed.notPressed) : Pressed.notPressed,
      // pressed: Pressed.notPressed,
      // decoration: decoration,
      decoration: decoration ?? BoxDecoration(
        borderRadius: BorderRadius.circular(borderRadius),
        border: Border.all(color: disable ? (disableColor ?? Colors.blueAccent) : backgroundColor),
        color: decoration == null ? (disable ? (disableColor ?? Colors.blueAccent) : backgroundColor) : null,
      ),
      borderRadius: borderRadius,
      // backgroundColor: decoration == null ? (disable ? (disableColor ?? AppColor.mainForbid) : backgroundColor) : null,
      animate: animate,
      // isThreeD: false,
      onPressed: () {
        if (disable) return;
        onPressed.call();
        // EasyThrottle.throttle('btn', throttle ?? const Duration(milliseconds: 500), () {
        //   onPressed.call();
        // });
      },
      child: child ?? Center(
        child: Text(content ?? '', style: const TextStyle(color: Colors.white)),
      ),
    );
  }
}
